package com.xing.acl.controller;


import com.xing.acl.entity.Permission;
import com.xing.acl.service.PermissionService;
import com.xing.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author xingfuao
 * @since 2022-04-19
 */
@RestController
@RequestMapping("/acl/permission")
@CrossOrigin
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取全部菜单
     *
     * @return
     */
    @ApiOperation(value = "查询所有菜单")
    @GetMapping
    public R indexAllPermission() {
        List<Permission> list = permissionService.queryAllMenuGuli();
        return R.ok().data("children", list);
    }

    /**
     * 递归删除菜单
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "递归删除菜单")
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id) {
        permissionService.removeChildById(id);
        return R.ok();
    }

    @ApiOperation(value = "给角色分配权限")
    @DeleteMapping("doAssign")
    public R doAssign(String roleId,String[] permissionId) {
       permissionService.saveRolePermissionRealtionShipGuli(roleId,permissionId);
        return R.ok();
    }



}

